<template>
  <div>
    <certificate-com :showCertificate="showCertificate" :certInfo='certificateInfo' @closeCertificate='closeCertificate'>
    </certificate-com>
  </div>
</template>

<script>
import { utilJs } from "@/utils/common.js";
import certificateCom from "./certificateCom.vue";

let clockInId = ''; //当前课程ID
export default {
  name: "MyCertificate",
  components: {
    certificateCom
  },
  props: [],
  data() {
    return {
      showCertificate: false,
      certificateInfo: {},
    };
  },
  created() {
    utilJs.appShare(this);
  },
  mounted() { },
  methods: {
    closeCertificate() {},

    //获取我的证书信息
    getMyCert() {
      utilJs.getMethod(`${global.apiurl}signCard/myHonor/${clockInId}`, res => {
        let titleArr = [];
        let titleName = res.column.certificateName || res.column.name;
        let firstTitle = titleName.substring(0, 13);
        let sencendTitle = titleName.substring(13, 26);
        firstTitle && titleArr.push(firstTitle);
        sencendTitle && titleArr.push(sencendTitle);
        let cardCover = res.column.cardCover2;
        let headimgurl = res.headimgurl || require('@/assets/defult_head.png');
        let qrcodeUrl = res.column.qrcodeUrl;

        let continuoueDay = null;
        if (res.column.type == 3 && res.column.enableDayData == 1) {
          continuoueDay = res.hasSignDay;
        } else if (res.column.type != 3 && res.column.enableContinuity == 1) {
          continuoueDay = res.continueDay;
        }
        let signDay = null;
        if (res.column.type == 3 && res.column.enableClearance == 1) {
          signDay = res.spendDays;
        } else if (res.column.type != 3 && res.column.enableDayData == 1) {
          signDay = res.hasSignDay;
        }
        let info = {
          isDefaultWord: res.column.isDefaultWord2,
          word: res.column.word2 || [],
          signDay: signDay,
          continuoueDay: continuoueDay,
          good: res.column.enableSelected == 1 ? res.hotNum : null,
          like: res.column.enableZan == 1 ? res.zanNum : null,
          titleArr: titleArr,
          nickname: res.nickname,
          cardCover: cardCover,
          customizeImage:res.column.customizeImage,
          certificateType:res.column.certificateType,
          customizeControl:res.column.customizeControl,
          avatarShowType:res.column.avatarShowType,
          shareDesc:res.column.shareDesc,
          headimgurl: headimgurl || require('@/assets/defult_head.png'),
          qrcodeImg: qrcodeUrl,
          iconSign: res.column.type == 2 ? require("@/assets/i/wap/clockIn/icon_num.png") : res.column.type == 3 ? require("../../../assets/i/wap/clockIn/icon_level_day.png") : require("../../../assets/i/wap/clockIn/icon_day.png"),
          iconContinue: res.column.type == 3 ? require("@/assets/i/wap/clockIn/icon_level_course.png") : require("../../../assets/i/wap/clockIn/icon_continue.png"),
          iconGood: require('@/assets/i/wap/clockIn/icon_good.png'),
          iconLike: require('@/assets/i/wap/clockIn/icon_like.png'),
        }
        this.certificateInfo = info;
        this.showCertificate = true;
      });
    },

    //分享
    wechatShare: function () {
      let title = window.localStorage.getItem("companyName");
      let shareImg = window.localStorage.getItem("shareLogo");
      let shareDesc = window.localStorage.getItem("shareDesc");
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?refereeId=${localStorage.getItem("userId")}`
      let shareIndexData = {
        shareUrl,
        title,
        shareImg,
        shareDesc,
      };
      let shareData = localStorage.getItem("homeWorkShareInfo") ? JSON.parse(localStorage.getItem("homeWorkShareInfo")) : shareIndexData;
      utilJs.wechatConfig(
        shareData.shareUrl,
        shareData.title,
        shareData.shareImg,
        shareData.shareDesc,
        function () { },
        true
      );
    },
    //手机端分享
    appShare: function () {
      let title = window.localStorage.getItem("companyName");
      let shareImg = window.localStorage.getItem("shareLogo");
      let shareDesc = window.localStorage.getItem("shareDesc");
      let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?refereeId=${localStorage.getItem("userId")}`
      let shareIndexData = {
        shareUrl,
        title,
        shareImg,
        shareDesc,
      };
      let shareData = localStorage.getItem("homeWorkShareInfo") ? JSON.parse(localStorage.getItem("homeWorkShareInfo")) : shareIndexData;
      utilJs.appShareTrue(
        shareData.title,
        shareData.shareImg,
        shareData.shareUrl,
        shareData.shareDesc
      );
    }
  },
  activated() {
    setDocumentTitle("我的证书");// eslint-disable-line
    this.showCertificate = false;
    this.certificateInfo = {};
    clockInId = this.$route.query.clockInId;
    this.getMyCert();
  },
  deactivated() { }
};
</script>
